﻿using System;
using System.Windows;
using WJP.Dependency;
using WJP.Logging;
using WJP.WPF;
using WJP.WPF.Shell;

namespace WJPClient
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application, IClientAppRuntime
    {
        public static IIocManager IocManager { get; private set; }

        public App()
        {
            this.DispatcherUnhandledException += App_DispatcherUnhandledException;

            var app = ClientApp.Register(this);

            IocManager = app.IocManager;
        }

        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            try
            {
                //WJP.WPF.App.MessageBox.Show(e.Exception.Message);
                MessageBox.Show(e.Exception.Message);
                e.Handled = true;
            }
            catch (Exception ex)
            {
                LogManager.Logger.Error("应用程序错误：", ex);
            }
        }
    }
}
